<?php
	include_once dirname(dirname(dirname(__FILE__))).'/inc/bootConfig.php';
	include_once '../checkLogin.php';
	include_once '../Public/login/checkUserGrade.php';
	
	$id = getRequest('id');
	if(!empty($id)){
		userLimit($username,1);
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
body {
	margin-left: 3px;
	margin-top: 0px;
	margin-right: 3px;
	margin-bottom: 0px;
}
.STYLE1 {
	color: #e1e2e3;
	font-size: 12px;
}
.STYLE6 {color: #000000; font-size: 12; }
.STYLE10 {color: #000000; font-size: 12px; }
.STYLE19 {
	color: #344b50;
	font-size: 12px;
}
.STYLE21 {
	font-size: 12px;
	color: #3b6375;
}
.STYLE22 {
	font-size: 12px;
	color: #295568;
}
-->
</style>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="24" bgcolor="#353c44">
        <?php 
    		include_once 'inc/userinfotop.html';
    	?></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>
    	<form action="" method="post" id="form1" onsubmit="return checkinfo();"> 
    	<table width="100%" align="center" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
	   	  <tr>
	        <td height="40"  bgcolor="d3eaef" class="STYLE6"  colspan='2' align="center"><h3>用户密码修改</h3></td>
	      </tr>
	      <tr <?php if(!empty($id)){echo " style='display:none' ";}?>>
	        <td width="40%" height="20" bgcolor="ffffff" class="STYLE6"><div align="right"><span class="STYLE10">请输入旧密码：</span></div></td>
	        <td width="60%" height="20" bgcolor="ffffff" class="STYLE6">
				<input type="password" value="<?php if(!empty($id)){echo $id;}?>" name="oldpwd" size="20"/>
			</td>
	      </tr>
	      <tr>
	        <td width="40%" height="20" bgcolor="ffffff" class="STYLE6"><div align="right"><span class="STYLE10">请输入新密码：</span></div></td>
	        <td width="60%" height="20" bgcolor="ffffff" class="STYLE6">
				<input type="password" value="" name="newpwd" size="20"/>
			</td>
	      </tr>
	      <tr>
	        <td width="40%" height="20" bgcolor="ffffff" class="STYLE6"><div align="right"><span class="STYLE10">再次输入新密码：</span></div></td>
	        <td width="60%" height="20" bgcolor="ffffff" class="STYLE6">
				<input type="password" value="" name="twopwd" size="20"/>
			</td>
	      </tr>
	      <tr>
	        <td width="40%" height="20" bgcolor="ffffff" class="STYLE6"><div align="right"><span class="STYLE10"></span></div></td>
	        <td width="60%" height="20" bgcolor="ffffff" class="STYLE6">
				<input type="submit" value="提交" name="submit" id="submit_s"/>
				<input type="reset" value="重置" name="reset" id="reset_s"/>
				<input type="button" value="返回" name="reset" id="reset_s" onclick="location.href='userList.php'"/>
			</td>
	      </tr>
      </table>
      </form>
    </td>
  </tr>
</table>
</body>
</html>
<script type="text/javascript">
function checkinfo(){
	var form = document.getElementById('form1');
	if(form.oldpwd.value.length<1){
		alert('请输入旧密码');
		return false;
	}
	if(form.newpwd.value.length<1){
		alert('请输入新密码');
		return false;
	}
	if(form.twopwd.value.length<1){
		alert('请再次输入新密码');
		return false;
	}
	if(form.twopwd.value != form.newpwd.value){
		alert('两次输入的新密码不一样，请重新输入');
		return false;
	}
}
</script>
<?php 
	if(isset($_POST['submit'])&&$_POST['submit']&&!empty($_POST['oldpwd'])){
		if(!empty($id)){
			if(User_User::updateUserPwdById($_POST['newpwd'],$id)){
				showmsgbox('用户密码修改成功','userList.php');
			}else{
				jstop('数据异常，请重试！');
			}			
		}
		if(User_Check::checkUserPwd($username,$_POST['oldpwd'])){
			if(User_User::updateUserPwdByName($_POST['newpwd'],$username)){
				showmsgbox('用户密码修改成功','../Public/login/logout.php');
			}else{
				jstop('数据异常，请重试！');
			}
		}else{
			jstop('你的旧密码输入 错误！请重新输入');
		}
	}
?>